{% extends "base_table.html" %}

{% block extra_scripts %}
  <script type="text/javascript">
    $(function() {
      var valueToggles = $('a.toggle-value');
      valueToggles.on('click', function(e) {
        e.preventDefault();
        var elem = $(this),
            truncated = elem.siblings('span.truncated'),
            full = elem.siblings('span.full');
        truncated.toggle();
        full.toggle();
      });
    });
  </script>
{% endblock %}

{% block content_title %}
  {{ super() }}
  <small>共 {{ ds_table.all().count() }} 行数据,共 {{ total_pages }} 页，第 {{ page }} 页。</small>
{% endblock %}

{% block content_tab_class %} active{% endblock %}

{% block inner_content %}
  {# add filters #}
  <table class="table table-striped">
    <thead>
      <tr>
        {% for column in columns %}
          <th>
            <a href="./?ordering={% if ordering == column %}-{% endif %}{{ column }}">{{ column }}</a>
          </th>
        {% endfor %}
      </tr>
    </thead>
    <tbody>
      {% for row in query %}
        <tr>
          {% for field in field_names %}
            {% set value = row[field] %}
            <td>
              {% if value is none %}
                NULL
              {% else %}
                {{ value|value_filter|safe }}
              {% endif %}
            </td>
          {% endfor %}
        </tr>
      {% endfor %}
    </tbody>
  </table>
  <nav>
    <ul class="pagination">
      <li class="{% if not previous_page %}disabled {% endif %}page-item">
        <a class="page-link" href="{{ url_for('table_content', table=table, page=1, ordering=ordering) }}">&laquo;</a>
      </li>
      <li class="{% if not previous_page %}disabled {% endif %}page-item">
        <a class="page-link" href="{{ url_for('table_content', table=table, page=previous_page, ordering=ordering) }}">&lsaquo;</a>
      </li>
      <li class="page-item disabled">
        <span class="page-link">{{ page }} / {{ total_pages }} 页 </span>
      </li>
      <li class="{% if not next_page %}disabled {% endif %}page-item">
        <a class="page-link" href="{{ url_for('table_content', table=table, page=next_page, ordering=ordering) }}">&rsaquo;</a>
      </li>
      <li class="{% if not next_page %}disabled {% endif %}page-item">
        <a class="page-link" href="{{ url_for('table_content', table=table, page=total_pages, ordering=ordering) }}">&raquo;</a>
      </li>
    </ul>
  </nav>
{% endblock %}
